package com.im.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.im.app.model.Conversations;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface ConversationsMapper extends BaseMapper<Conversations> {

    @Select(value = "select * from conversations where owner_user_id = #{ownerUserId} and group_id = #{groupId} limit 1")
    Conversations selectByGroup(@Param("ownerUserId") String ownerUserId, @Param("groupId") String groupId);

    @Select(value = "select * from conversations where owner_user_id = #{ownerUserId} and user_id = #{userId} limit 1")
    Conversations selectByUser(@Param("ownerUserId") String ownerUserId,@Param("userId") String userId);

    @Update(value = "update conversations set is_pinned = #{isPinned} where conversation_id=#{conversationId}")
    int updateIsPinned(@Param("isPinned") Integer isPinned,@Param("conversationId") String conversationId);

    @Update(value = "update conversations set unread_count = 0 where conversation_id=#{conversationId}")
    int clearUnreadCount(@Param("conversationId") String conversationId);
}

